package com.ayou.mapping;

import com.ayou.parsing.GenericTokenParser;
import com.ayou.parsing.ParameterTokenHandler;
import com.sun.deploy.ui.AboutDialog;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import java.util.List;

/**
 * @description:
 * @author: ayouman
 * @date: 2024/7/1 22:20
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@SuperBuilder
public class MappedStatement {
    private String id;  // com.demo.mapper.UserMapper.selectOne
    private String sql;
    private Class resultType;
    private SqlCommandType sqlCommandType;
    private Boolean selectMany;

    public BoundSql getBoundSql() {
        ParameterTokenHandler parameterTokenHandler = new ParameterTokenHandler();
        GenericTokenParser genericTokenParser = new GenericTokenParser(parameterTokenHandler);
        String sql = genericTokenParser.parse(this.sql);
        List<String> parameterMappings = parameterTokenHandler.getParameterMappings();
        return BoundSql.builder().sql(sql).parameterMappings(parameterMappings).build();
    }
}
